from flask import Flask, request, jsonify

app = Flask(__name__)

# 简单的 GET 请求接口
@app.route('/api/hello', methods=['GET'])
def hello():
    return jsonify({"message": "Hello, World!"})

# 带参数的 GET 请求接口
@app.route('/api/greet', methods=['GET'])
def greet():
    name = request.args.get('name', 'Guest')
    return jsonify({"message": f"Hello, {name}!"})

# POST 请求接口
@app.route('/api/add', methods=['POST'])
def add_numbers():
    data = request.get_json()
    if not data or 'num1' not in data or 'num2' not in data:
        return jsonify({"error": "Please provide num1 and num2"}), 400
    
    result = data['num1'] + data['num2']
    return jsonify({"result": result})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True) 